<?php

declare (strict_types = 1);

namespace app\store\controller;

use app\store\model\Order as OrderModel;
use think\response\Json;

/**
 * 订单管理
 * Class Order
 * @package app\store\controller
 */
class Order extends Controller
{
    /**
     * 订单列表
     * @param string $dataType
     * @return Json
     */
    public function list(string $dataType): Json
    {
        $params = $this->request->param();
        $this->validate(
            $params,
            [
                'order_type' => 'integer',   //1抽选订单 2秒杀订单 3抽赏订单 4邮费订单
                'payType' => 'integer',   // 10余额支付 20微信支付
               // 'order_no' => '',  //订单号
            ]
        );
        // 订单列表
        $model = new OrderModel;
        $list = $model->getList($dataType, $this->request->param());
        return $this->renderSuccess(compact('dataType', 'list'));
    }

    /**
     * 订单详情
     * @param int $orderId
     * @return Json
     */
    public function detail(int $orderId):Json
    {
        // 订单详情
        $model = new OrderModel;
        if (!$detail = $model->getDetail($orderId)) {
            return $this->renderError('未找到该订单记录');
        }
        return $this->renderSuccess(compact('detail'));
    }

}
